<%@ include file="../system/HeaderStrutsForm.jsp" %>
<html>
  <head>

    <bean:message key="page.css"/>
    <bean:message key="page.script"/>
  </head>
  <center>
    <body>
      <table class="mainTable" style='width:99%;'>
        <tr>
          <td>
            <html:form 
                action="lov/EmpresaSetorLov.do"
                method="POST"
                styleClass="baseForm">

              <table class="bannerTable" style='width:99%;'>
                <tr>
                  <td class=tableHeader>
                    Pesquisa de Setores
                  </td>
                </tr>
              </table>
              <table class="messageTable" style='width:99%;'>
                <tr>
                  <td class="messageHeader">
                    <bean:message key="div.campos*"/>
                    <html:errors/>
                  </td>
                </tr>
              </table>
              <table class="itemTable" style='width:99%;'>
                <tr>
                  <td class="formLabel">
                    <span class="spamFormLabel" >
                      Empresa
                    </span>
                  </td>
                  <td class="formField">
                    <html:select property="empresa" styleClass="baseField">
                      <html:options 
                          property="empresaList"
                          labelProperty="empresaLabelList"
                          styleClass="baseOptions"/>
                    </html:select>
                  </td>
                </tr>
              </table>
              <table class="buttonTable" style='width:99%;'>
                <tr>
                  <td class="buttonItem">
                    <html:submit 
                        accesskey="r"
                        styleClass="baseButton"
                        property="refresh_action">


                      <bean:message 
                          bundle="ApplicationResources"
                          key="jsp.refresh"/>
                    </html:submit>
                  </td>
                </tr>
              </table>
            </html:form>

            <%
            {
              %>
              <form class="baseForm" >
                <table class="bannerTable" style=width:99%;>
                  <tr>
                    <td class="tableHeader">
                      Lista de Setores por Empresa
                    </td>
                  </tr>
                </table>
                <table 
                    id="TRbl_report_Setor_empresa"
                    class="reportTable"
                    style=width:99%;
                     >

                  <%
                  int counterbl_report_Setor_empresa=0;
                  %>
                  <%
                  com.egen.util.jdbc.JdbcUtil j = null;
                  try {
                    j = new com.egen.util.jdbc.JdbcUtil();
                    br.com.werp.suporte.dbobj.table.Setor_empresa t_setor_empresa = new br.com.werp.suporte.dbobj.table.Setor_empresa();
                    java.util.Vector res_Setor_empresa = null;
                    try {
                      String[][] select =  null;
                      Object[][] where = null;
                    where = new Object[][]{{"stem_id","like",(String)request.getParameter("empresa")}

                    };
                    String[] groupby =  null;
                    String[] having =  null;
                    String[] order = {};
                    res_Setor_empresa = j.select(t_setor_empresa,select,where,groupby,having,order);
                  } catch (Exception e){
                    session.setAttribute("exception",com.egen.util.system.Error.getDescription(e));
                    %>
                    <jsp:forward page="/system/ErrorPage.jsp"/>
                    <%
                  }
                  if (res_Setor_empresa!=null && res_Setor_empresa.size()>0) {
                    if ( ((String)request.getParameter("_ordered"))!=null && ((String)request.getParameter("_ordered")).length()>0 ) {
                      boolean reverse = false;
                      if ( ((String)request.getParameter("_reverse"))!=null && ((String)request.getParameter("_reverse")).length()>0 && ((String)request.getParameter("_reverse")).equals("true") ){
                        reverse = true;
                      }
                      try {
                        res_Setor_empresa = com.egen.util.text.Sort.execute(res_Setor_empresa,((String)request.getParameter("_ordered")),reverse);
                      } catch (Exception e) {}
                    }
                    int stem_id =  0;
                    int stem_empresa =  0;
                    int stem_setor =  0;
                    java.lang.String stor_descricao =  null;
                    java.lang.String empr_descricao =  null;
                    int i_bl_report_Setor_empresa = 0;
                    t_setor_empresa = (br.com.werp.suporte.dbobj.table.Setor_empresa)res_Setor_empresa.elementAt(i_bl_report_Setor_empresa);
                    stem_id = t_setor_empresa.getStem_id();
                    stem_empresa = t_setor_empresa.getStem_empresa();
                    stem_setor = t_setor_empresa.getStem_setor();
                    stor_descricao = "";
                    {
                      br.com.werp.suporte.dbobj.table.Setor $cr_db_object = new br.com.werp.suporte.dbobj.table.Setor();
                      Object[][] where = {
                      {"stor_id","=",new Integer(stem_setor)}
                      };
                      java.util.Vector results = j.select($cr_db_object, where, null);
                      if (results!=null && results.size()>0) {
                        $cr_db_object = (br.com.werp.suporte.dbobj.table.Setor)results.elementAt(0);
                        stor_descricao = $cr_db_object.getStor_descricao() + "";
                      }
                      };
                      empr_descricao = "";
                      {
                        br.com.werp.suporte.dbobj.table.Empresa $cr_db_object = new br.com.werp.suporte.dbobj.table.Empresa();
                        Object[][] where = {
                        {"empr_id","=",new Integer(stem_empresa)}
                        };
                        java.util.Vector results = j.select($cr_db_object, where, null);
                        if (results!=null && results.size()>0) {
                          $cr_db_object = (br.com.werp.suporte.dbobj.table.Empresa)results.elementAt(0);
                          empr_descricao = $cr_db_object.getEmpr_descricao() + "";
                        }
                        };
                        %>
                        <tr class="reportHeader" >
                          <td >
                            <span 
                                class="spamHeaderLabel"
                                style="text-align:center;width:100%;">

                              Setor
                            </span>
                          </td>
                          <td >
                            <span 
                                class="spamHeaderLabel"
                                style="text-align:center;width:100%;">

                              Empresa
                            </span>
                          </td>
                        </tr>
                        <%
                        while (i_bl_report_Setor_empresa<res_Setor_empresa.size()){
                          counterbl_report_Setor_empresa++;
                          String style="";
                          if (!((i_bl_report_Setor_empresa%2)!=0)) {
                            style="class=rowColor";
                          } else {
                            style="class=rowBlank";
                          }
                          %>
                          <tr 
                              <%=
                              style
                              %>
                              id='TRbl_report_Setor_empresa<%=counterbl_report_Setor_empresa%>'
                          >


                            <td class="reportcolumn"  >
                              <a 
                                  href="javascript:setLov('<%= stem_empresa %>','<%= stem_setor %>','<%= stor_descricao %>','<%= empr_descricao %>')"
                                  target="_self"
                                  STYLE="cursor:hand">


                                <span 
                                    class="spamColumnLabel"
                                    style="text-align:center;">

                                  <%= stor_descricao %>
                                </span>
                              </a>
                            </td>
                            <td class="reportcolumn"  >
                              <span 
                                  class="spamColumnLabel"
                                  style="text-align:center;">

                                <%= empr_descricao %>
                              </span>
                            </td>
                          </tr>
                          <%
                          if (++i_bl_report_Setor_empresa >= res_Setor_empresa.size()) {
                            break;
                          }
                          t_setor_empresa = (br.com.werp.suporte.dbobj.table.Setor_empresa)res_Setor_empresa.elementAt(i_bl_report_Setor_empresa);
                          stem_id = t_setor_empresa.getStem_id();
                          stem_empresa = t_setor_empresa.getStem_empresa();
                          stem_setor = t_setor_empresa.getStem_setor();
                          stor_descricao = "";
                          {
                            br.com.werp.suporte.dbobj.table.Setor $cr_db_object = new br.com.werp.suporte.dbobj.table.Setor();
                            Object[][] where = {
                            {"stor_id","=",new Integer(stem_setor)}
                            };
                            java.util.Vector results = j.select($cr_db_object, where, null);
                            if (results!=null && results.size()>0) {
                              $cr_db_object = (br.com.werp.suporte.dbobj.table.Setor)results.elementAt(0);
                              stor_descricao = $cr_db_object.getStor_descricao() + "";
                            }
                            };
                            empr_descricao = "";
                            {
                              br.com.werp.suporte.dbobj.table.Empresa $cr_db_object = new br.com.werp.suporte.dbobj.table.Empresa();
                              Object[][] where = {
                              {"empr_id","=",new Integer(stem_empresa)}
                              };
                              java.util.Vector results = j.select($cr_db_object, where, null);
                              if (results!=null && results.size()>0) {
                                $cr_db_object = (br.com.werp.suporte.dbobj.table.Empresa)results.elementAt(0);
                                empr_descricao = $cr_db_object.getEmpr_descricao() + "";
                              }
                              };
                            }
                          }
                        } catch (Exception e) {
                          session.setAttribute("exception",com.egen.util.system.Error.getDescription(e));
                          %>
                          <jsp:forward page="/system/ErrorPage.jsp"/>
                          <%
                        } finally {
                        if(j!=null){j.close(); }
                      }
                      %>
                    </table>
                    <script>
                      function setLov(STEM_EMPRESA,STEM_SETOR,STOR_DESCRICAO,EMPR_DESCRICAO) {
                        <% { String returnBlock = ((request.getParameter("returnBlock")!=null)?request.getParameter("returnBlock"):(String)session.getAttribute("returnBlock_bl_report_Setor_empresa"));
                        if (returnBlock!=null && returnBlock.length()>0) {
                          session.setAttribute("returnBlock_bl_report_Setor_empresa",returnBlock);%>
                          returnBlock = <%= returnBlock %>;
                          <% } else { %>
                          returnBlock = 0;
                          <% } } %>
                          <% { String return0 = ((request.getParameter("return0")!=null)?request.getParameter("return0"):(String)session.getAttribute("return0_bl_report_Setor_empresa"));
                          if (return0!=null && return0.length()>0) {
                            session.setAttribute("return0_bl_report_Setor_empresa",return0);%>
                            if (opener.document.forms[returnBlock].<%= return0 %>!=null) { opener.document.forms[returnBlock].<%= return0 %>.value=STEM_EMPRESA };
                            <% } else { %>
                            if (opener.document.forms[returnBlock].stem_empresa!=null) { opener.document.forms[returnBlock].stem_empresa.value=STEM_EMPRESA };
                            <% } } %>
                            <% { String return1 = ((request.getParameter("return1")!=null)?request.getParameter("return1"):(String)session.getAttribute("return1_bl_report_Setor_empresa"));
                            if (return1!=null && return1.length()>0) {
                              session.setAttribute("return1_bl_report_Setor_empresa",return1);%>
                              if (opener.document.forms[returnBlock].<%= return1 %>!=null) { opener.document.forms[returnBlock].<%= return1 %>.value=STEM_SETOR };
                              <% } else { %>
                              if (opener.document.forms[returnBlock].stem_setor!=null) { opener.document.forms[returnBlock].stem_setor.value=STEM_SETOR };
                              <% } } %>
                              <% { String return2 = ((request.getParameter("return2")!=null)?request.getParameter("return2"):(String)session.getAttribute("return2_bl_report_Setor_empresa"));
                              if (return2!=null && return2.length()>0) {
                                session.setAttribute("return2_bl_report_Setor_empresa",return2);%>
                                if (opener.document.forms[returnBlock].<%= return2 %>!=null) { opener.document.forms[returnBlock].<%= return2 %>.value=STOR_DESCRICAO };
                                <% } else { %>
                                if (opener.document.forms[returnBlock].stor_descricao!=null) { opener.document.forms[returnBlock].stor_descricao.value=STOR_DESCRICAO };
                                <% } } %>
                                <% { String return3 = ((request.getParameter("return3")!=null)?request.getParameter("return3"):(String)session.getAttribute("return3_bl_report_Setor_empresa"));
                                if (return3!=null && return3.length()>0) {
                                  session.setAttribute("return3_bl_report_Setor_empresa",return3);%>
                                  if (opener.document.forms[returnBlock].<%= return3 %>!=null) { opener.document.forms[returnBlock].<%= return3 %>.value=EMPR_DESCRICAO };
                                  <% } else { %>
                                  if (opener.document.forms[returnBlock].empr_descricao!=null) { opener.document.forms[returnBlock].empr_descricao.value=EMPR_DESCRICAO };
                                  <% } } %>
                                  window.close();
                                }
                              </script>
                            </form>
                            <%
                          }
                          %>
                        </td>
                      </tr>
                    </table>
                  </body>
                </center>
              </html>
